/*
 * Copyright 2017 HugeGraph Authors
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with this
 * work for additional information regarding copyright ownership. The ASF
 * licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.baidu.hugegraph.util;

import java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Pattern;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections.CollectionUtils;

public final class HubbleUtil {

    public static final Pattern HOST_PATTERN = Pattern.compile(
            "(([0-9]{1,3}\\.){3}[0-9]{1,3}|" +
            "([0-9A-Za-z_!~*'()-]+\\.)*[0-9A-Za-z_!~*'()-]+)$"
    );

    public static Date nowDate() {
        return new Date();
    }

    public static Instant nowTime() {
        return Instant.now();
    }

    public static boolean equalCollection(Collection<?> c1, Collection<?> c2) {
        if (c1 != null && c2 == null || c1 == null && c2 != null) {
            return false;
        }
        return c1 == null || CollectionUtils.isEqualCollection(c1, c2);
    }

    public static String generateSimpleId() {
        return UUID.randomUUID().toString();
    }

    public static String md5(String rawText) {
        return DigestUtils.md5Hex(rawText);
    }
}
